<?php

$params = require(__DIR__ . '/params.php');

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'language'=>'zh-CN',
//    'language'=>'en',
    'bootstrap' => ['log'],
    'modules' => [
        // 微信模块
        'wechat' => [
            'class' => 'callmez\wechat\Module',
            'adminId' => 100 // 这里填写管理员ID(拥有wechat最高管理权限), 默认为当前模板的admin账号
        ],
        'abc' => [
            'class' => 'app\modules\wechat\modules\test\Module',
            'adminId' => 120 // 这里填写管理员ID(拥有wechat最高管理权限), 默认为当前模板的admin账号
        ],
    ],



    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'Or2WOCx-RoEC6Bk-2EADf_tlmtynkieR',
            'parsers' => [ // 微信使用了angular.js 该设置用来解析Angular POST 提交的数据
                'application/json' => 'yii\web\JsonParser',
            ]
        ],
        'formatter' => [
            'class' => 'yii\i18n\Formatter',
            'dateFormat' => 'php:d-M-Y',
            'datetimeFormat' => 'Y-M-d H:i:s',
            'timeFormat' => 'php:H:i:s',
        ],
        'i18n' => [
            'translations' => [
                'app' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@app/messages',
                    //'sourceLanguage' => 'en-US',
                    'fileMap' => [
                        'app' => 'app.php',
                        'app/error' => 'error.php',
                    ],
                ],
            ],
        ],
        'urlManager'=>array(
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules'=>array(
                'home/recharge/<type:\d+>' => '/wechat/mobile/home/recharge',
                'home/<action:\w+>' => '/wechat/mobile/home/<action>',
//                'home/recharge/<type:\d+>/<id:\d+>' => '/wechat/mobile/home/recharge/<action>',
                'home/article/<id:\d+>' => '/wechat/mobile/home/article',
                'profile/<action:\w+>' => '/wechat/mobile/profile/<action>',
                'profile/<action:\w+>/<id:\d+>' => '/wechat/mobile/profile/<action>',
                'profile' => '/wechat/mobile/profile',
//                'profile/agency' => '/wechat/mobile/profile/agency',
//                'profile/order' => '/wechat/mobile/profile/order',
//                'profile/question' => '/wechat/mobile/profile/question',
//                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
//                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                '<controller:\w+>/<action:\w+>/<type:\d+>'=>'<controller>/<action>',
            ),
        ),
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning','info'],
                ],
            ],
        ],
        'db' => require(__DIR__ . '/db.php'),
    ],
    'params' => $params,
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
//    $config['bootstrap'][] = 'debug';
//    $config['modules']['debug'] = 'yii\debug\Module';

    $config['bootstrap'][] = 'gii';
//    $config['modules']['gii'] = 'yii\gii\Module';
    $config['modules']['gii']=[
        'class' => 'yii\gii\Module',
        'allowedIPs' => ['::1','127.0.0.1'], //只允许本地访问gii
        'generators'=> [
            /*重新定义gii model & crud的生成模板*/
            'module'=> [
//                'class' => 'yii\gii\generators\module\Generator',
                'class' => 'callmez\wechat\generators\module\Generator',
                'templates'=> [
                    'backend'=>'@callmez/wechat/generators/module/default'
                ]
            ],
//            'model'=> [
//                'class' => 'yii\gii\generators\model\Generator',
//                'baseClass'=> 'base\BaseActiveRecord',
//                'ns'=> 'common\models',
//                'templates'=> [
//                    'common'=>'@common/gii/generators/model/default',
//                    'backend'=>'@common/gii/generators/model/backend'
//                ]
//            ],
//            'crud'=> [
//                'class' => 'yii\gii\generators\crud\Generator',
//                'templates'=> [
//                    'backend'=>'@common/gii/generators/crud/default'
//                ],
//                'baseControllerClass' => 'BaseBackendController',
//                'messageCategory'=> 'backend'
//            ]
//            'module'=>[
//                'class' => 'callmez\wechat\generators\wechat\Generators'
//            ]
        ]

    ];
}

return $config;
